package data_structure;

import java.util.HashSet;
import java.util.Set;

public class leetcode_0202 {
    public static void main(String[] args) {
        System.out.println(isHappy(19));
    }
    public static boolean isHappy(int n) {
        int current=n;
        Set<Integer> set=new HashSet<>();
        set.add(current);
        while(true){
            current=action(current);
            if(current==1) return true;
            if(set.contains(current)) return false;
            else set.add(current);
        }
    }
    public static int action(int n){
        int tem=0;
        while(n>0){
            tem+=(n%10)*(n%10);
            n/=10;
        }
        return tem;
    }
}
